package com.charge.service.impl;

import com.charge.dao.ReportMapping;
import com.charge.dto.ReportDTO;
import com.charge.service.ReportService;
import com.charge.util.DozerUtils;
import com.charge.vo.ReportVO;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Description :
 * Author : 91658
 * Date : 2018/6/12 10:34
 **/
@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private ReportMapping reportMapping;

    @Override
    public List<ReportVO> annualReport(ReportDTO reportDTO) {
        ReportDTO queryDTO = DozerUtils.convert(reportDTO, ReportDTO.class);
        if (StringUtils.isNotEmpty(reportDTO.getBeginDate())) {
            String beginDate = reportDTO.getBeginDate();
            queryDTO.setBeginDate(beginDate.substring(0, 4));
        }
        if (StringUtils.isNotEmpty(reportDTO.getEndDate())) {
            String endDate = reportDTO.getEndDate();
            queryDTO.setEndDate(endDate.substring(0, 4));
        }
        return reportMapping.annualReport(queryDTO);
    }

    @Override
    public List<ReportVO> quarterReport(ReportDTO reportDTO) {
        ReportDTO queryDTO = DozerUtils.convert(reportDTO, ReportDTO.class);
        if (StringUtils.isNotEmpty(reportDTO.getBeginDate())) {
            String beginDate = reportDTO.getBeginDate();
            queryDTO.setBeginDate(beginDate.substring(0, 4));
        }
        if (StringUtils.isNotEmpty(reportDTO.getEndDate())) {
            String endDate = reportDTO.getEndDate();
            queryDTO.setEndDate(endDate.substring(0, 4));
        }
        return reportMapping.quarterReport(queryDTO);
    }

    @Override
    public List<ReportVO> monthlyReport(ReportDTO reportDTO) {
        ReportDTO queryDTO = DozerUtils.convert(reportDTO, ReportDTO.class);
        if (StringUtils.isNotEmpty(reportDTO.getBeginDate())) {
            String beginDate = reportDTO.getBeginDate();
            queryDTO.setBeginDate(beginDate.substring(0, 7));
        }
        if (StringUtils.isNotEmpty(reportDTO.getEndDate())) {
            String endDate = reportDTO.getEndDate();
            queryDTO.setEndDate(endDate.substring(0, 7));
        }
        return reportMapping.monthlyReport(queryDTO);
    }

    @Override
    public List<ReportVO> weekReport(ReportDTO reportDTO) {
        return reportMapping.weekReport(reportDTO);
    }

    @Override
    public List<ReportVO> weekDateReport(ReportDTO reportDTO) {
        return reportMapping.weekDateReport(reportDTO);
    }

    @Override
    public List<ReportVO> daysReport(ReportDTO reportDTO) {
        return reportMapping.daysReport(reportDTO);
    }

    @Override
    public List<ReportVO> accountReport(ReportDTO reportDTO) {
        return reportMapping.accountReport(reportDTO);
    }

    @Override
    public List<ReportVO> projectReport(ReportDTO reportDTO) {
        if (reportDTO.getPaymentsType() == 1) {
            return reportMapping.projectSpendingReport(reportDTO);
        }
        if (reportDTO.getPaymentsType() == 2) {
            return reportMapping.projectIncomeReport(reportDTO);
        }
        return null;
    }
}
